<template>
  <Modal v-model="modal" title="续时">
    <Form :label-width="100" ref="form" :model="form" :rules="rules">
      <FormItem label="时间(天)：" prop="day_num">
        <Input v-model="form.day_num" placeholder="请输入天数"></Input>
      </FormItem>
    </Form>
    <div slot="footer">
      <Button class="mr" size="large" type="text" @click="closeModal">取消</Button>
      <Button type="primary" size="large" :disabled="disabled" @click="onSave">确定</Button>
    </div>
  </Modal>
</template>
<script>
export default {
  data() {
    return {
      modal: false,
      disabled: false,
      storeContractId: null,
      typeList: [{
        name: '设计师',
        id: '1'
      }, {
        name: '制版',
        id:' 2'
      }, {
        name: '制样',
        id: '3'
      }],
      professionList: [{
        name: '专职',
        id: ' 0'
      }, {
        name: '兼职',
        id: '1'
      }],
      form: {
        day_num: '',
        componany_id: ''
      },
      rules: {
        type: [ {required: true, message: "请选择职业", trigger: "change"} ],
        day_num: [ {required: true,  message: "请输入天数", trigger: "blur"} ]
      }
    }
  },
  methods: {
    updataForm(id) {
      this.$refs.form.resetFields()
      this.form = {
        day_num: ''
      }
      this.disabled =  false
      this.company_id = id
      this.openModal()
    },
    openModal() {
      this.modal = true;
    },
    closeModal() {
      this.modal = false
    },
    onSave() {
      if (this.disabled) return
      this.disabled = true
      this.$refs["form"].validate(valid => {
        let param = {
          day_num: this.form.day_num,
          company_id: this.company_id
        }
        if (valid) {
          this.$jsonPost(`/company/addTime`, param).then(data => {
            this.closeModal()
            this.$Notice.success({
              title: '操作成功'
            })
            this.$emit("complete")
            this.disabled = false
          }).catch(() => {
            this.closeModal()
            this.disabled = false
          })
        } else {
          this.disabled = false
        }
      })
    }
  }
}
</script>
